package cn.wolfcode.wolf2w.business.listener;

import cn.wolfcode.wolf2w.business.service.IStrategyService;
import cn.wolfcode.wolf2w.common.redis.service.RedisService;
import cn.wolfcode.wolf2w.common.redis.util.RedisKeys;
import com.alibaba.nacos.shaded.org.checkerframework.checker.units.qual.A;
import com.alibaba.nacos.shaded.org.checkerframework.checker.units.qual.K;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

@Component
public class RedisStatisDataInitListener implements ApplicationListener<ContextRefreshedEvent> {

    @Autowired
    private IStrategyService strategyService;

    @Autowired
    private RedisService redisService;

    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
//        System.err.println("strategy攻略服务初始化");

        String key = RedisKeys.STRATEGY_STATIS_HASH_INIT.join("init");
        Boolean b = redisService.hasKey(key);
        if(b){
            System.out.println("redis statisHash数据已初始化完成");
            return;
        }
        redisService.setCacheObject(key,1);
        strategyService.statisHashInit();
        System.out.println("redis statisHash数据初始化完成");
    }
}
